#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, x, sum, i, a, b, temp;
    priority_queue<int, vector<int>, greater<int> > temps;
    cin >> n;
    for (i = 0; i < n; i++) cin >> x, temps.push(x);
    sum = 0;
    while (temps.size() > 1)
    {
        a = temps.top();
        temps.pop();
        b = temps.top();
        temps.pop();
        temp = a + b;
        sum += temp;
        temps.push(temp);
    }
    cout << sum;
    
    return 0;
}
